package com.briup.day26;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class Test_UDPSend {
    public static void main(String[] args) throws Exception {
        //实例化Socket对象 负责接收和发送数据
        DatagramSocket socket = new DatagramSocket();
        byte[] buff = "hello 你好接收端".getBytes();
        String ip="127.0.0.1";
        //实例化packet对象 负责封装接受和发送数据
        DatagramPacket packet = new DatagramPacket(buff, 0,buff.length, InetAddress.getByName(ip),8888);
        socket.send(packet);
        System.out.println("数据发生成功");
        System.out.println(new String(buff,0,packet.getLength()));

        socket.close();
    }
}
